<?php
// +----------------------------------------------------------------------
// | quickadmin框架 [ quickadmin框架 ]
// +----------------------------------------------------------------------
// | 版权所有 2020~2022 南京新思汇网络科技有限公司
// +----------------------------------------------------------------------
// | 官方网站: https://www.quickadmin.top
// +----------------------------------------------------------------------
// | Author: zs <909883663@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;

use app\BaseController;

use think\App;
use think\facade\Db;
use util\Excel;

/*
 * @Description: index
 * @Date: 2021-05-25 14:57:43
 */

class Zt extends BaseController
{

    protected $model = null;

    public function __construct(App $app)
    {
        parent::__construct($app);
    }


    // 首页
    public function index()
    {

        $data = Excel::import('storage/zt.xls');
        // halt($data);
        unset($data[1]);
        foreach ($data as  $value) {
            table('warehouse_coding')->where(['wc_coding' => $value[0]])->update(['wc_new_price' => $value[1]]);
        }
        return success('更新成功');
    }


    // 首页
    public function ttt()
    {

        $data = Excel::import('storage/wz.xls');
        unset($data[1]);
        foreach ($data as  $value) {
            //处理时间
            $date = date_parse_from_format('Y-m-d', $value[4]);
            $time = date('Y-m-d H:i:s', mktime(0, 0, 0, $date['month'], $date['day'], $date['year']));
            //查询平台
            // $advplatform_where[] = ['title', 'LIKE', "%{$value}%"];
            //查询平台
            $query_field = 'title';
            $advplatform_where[] = [$query_field, 'LIKE', "%{$value[2]}%"];
            $advplatform = table('advplatform')->where($advplatform_where)->find();
            halt($advplatform_where, $advplatform);
            //查询账号id和adminid
            $advplat_where[] = ['account', 'in', $value[0]];
            // $advplat = table('advplat')->where(['account' => $value[0]])->find();
            $advplat = table('advplat')->where('find_in_set(' . $value[0] . ',account)')->find();
            $arr_insert = [
                'cost' => isset($value[3]) ? $value[3] : 0,
                'plat' => isset($advplatform['title']) ?  $advplatform['id'] : 0,
                'plat_account' => isset($advplat['id']) ?  $advplat['id'] : 0,
                'admin_id' => isset($advplat['admin_ids']) ?  $advplat['admin_ids'] : 0,
                'create_time' => $time ?  $time : 0,
            ];
            table('advertising')->insert($arr_insert);
        }
        return 11;
    }
}
